package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.Account;
import com.example.entity.Student;
import com.example.entity.vo.StudentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
@DS("slave")
public interface StudentMapper extends BaseMapper<Student> {

// todo 文章：在 mybatis 中使用泛型

//    @Select("select s.id, s.name, s.parent_id as parentId " +
//            "from student s " +
//            "where ${ew.sqlSegment}")
//    Page<StudentVO> getStudentList(@Param(Constants.WRAPPER) QueryWrapper<com.example.entity.Student> queryWrapper, Page<StudentVO> page);

    @Select("select s.id, s.name, s.parent_id as parentId " +
            "from student s " +
            "where ${ew.sqlSegment}")
    @ResultMap("studentResultMap")
    <T> Page<T> getStudentList(@Param(Constants.WRAPPER) QueryWrapper<T> queryWrapper, Page<T> page);
}
